package zhaomh.zlogin;

import org.bukkit.configuration.file.YamlConfiguration;

import java.io.File;
import java.util.List;

import static zhaomh.zlogin.Tools.PLUGIN;
import static zhaomh.zlogin.Tools.colorReplace;

public class Language{
    //语言文件
    private static final String FILE_NAME = "message.yml";
    public static YamlConfiguration language;
    public static void reloadLanguage(){
        File language_file = new File(PLUGIN.getDataFolder(),FILE_NAME);
        if (!language_file.exists()) {
            //读取resources中的language.yml文件并保存到插件数据目录(plugins/ModName/)
            PLUGIN.saveResource(FILE_NAME, false);
        }
        language = YamlConfiguration.loadConfiguration(language_file);
    }
    public static String get(String path) {
        String string = language.getString(path);
        if (string == null)
            return null;
        return colorReplace(string);
    }
    public static List<String> getList(String path) {
        List<String> stringList = language.getStringList(path);
        stringList.replaceAll(Tools::colorReplace);
        return stringList;
    }
    public static void initialize(){
        reloadLanguage();
    }
}
